package com.tboss.template.system.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tboss.template.system.dao.MappingUserInfoGroupDao;
import com.tboss.template.system.dto.MapUsrGrpDto;
import com.tboss.template.system.dto.UserInfoDto;

@Service
public class MappingUserInfoGroupService {

	@Autowired MappingUserInfoGroupDao mapUsrInfoGrpDao;
	
	public Integer checkGrpChgChkField(String usrId){
		return this.mapUsrInfoGrpDao.checkGrpChgChkField(usrId);
	}
	
	public void delMapUsrInfoGrp(String usrId){
		this.mapUsrInfoGrpDao.delMapUsrInfoGrp(usrId);
	}
	
	public void addMapUsrInfoGrp(UserInfoDto dto){
		String usrId = dto.getUsrId();

		this.delMapUsrInfoGrp(usrId);
		List<String> grpList = dto.getUsrGroupLst();
		int cnt = grpList.size();
		for(int i = 0; i < cnt; i++){
			MapUsrGrpDto mapDto = new MapUsrGrpDto();
			mapDto.setUsrId(usrId);
			mapDto.setGrpId(grpList.get(i));
			mapDto.setGrpOrder(i);
			mapDto.setGrpInitChk(dto.getGrpInitChk());
			
			this.mapUsrInfoGrpDao.addMapUsrInfoGrp(mapDto);
		}
	}
	
}
